package com.stu.serive.impl;

import com.stu.Dto.ComplaintDTO;
import com.stu.constant.StatusConstant;
import com.stu.context.BaseContext;
import com.stu.mapper.ComplaintMapper;
import com.stu.pojo.Complaint;
import com.stu.pojo.StayApplication;
import com.stu.serive.ComplaintService;
import com.stu.serive.aTService;
import com.stu.vo.ComplaintVo;
import com.stu.vo.StayApplicationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

@Service
@Slf4j
public class ComplaintImpl implements ComplaintService {

    @Autowired
    private ComplaintMapper complaintMapper;

    /**
     * 添加投诉信息
     * @param complaintDTO
     */
    public void insertComplaint(ComplaintDTO complaintDTO) {
        //获取学生id
        Long currentId = BaseContext.getCurrentId();
        //创建实体
        Complaint complaint = new Complaint();
        //赋值
        BeanUtils.copyProperties(complaintDTO, complaint);
        complaint.setStuId(Math.toIntExact(currentId));
        complaint.setComplaintTime(LocalDateTime.now());
        //添加操作
        complaintMapper.insertComplaint(complaint);
    }

    /**
     * 查询投诉结果
     * @return
     */
    public List<ComplaintVo> selectComplaint() {
        //获取学生id
        Long currentId = BaseContext.getCurrentId();
        //根据学生id查询 留校申请表和学生基础信息表 获取Vo数据
        List<ComplaintVo> complaintVoList = complaintMapper.selectComplaint(currentId);

        //对审核状态进行判断
        for (ComplaintVo complaintVo : complaintVoList) {
          if (complaintVo.getComplaintReply() == null){
              complaintVo.setComplaintReply("暂未回复");
          }
        }
        return complaintVoList;
    }
}
